//
//  AppDelegate.m
//  LightControl
//
//  Created by CKF on 2025/6/30.
//

#import "AppDelegate.h"
#import "BlueToothViewController.h"
#import "TabbarController.h"
#import "SSKeychain.h"
#import "CommonMethod.h"
#import "SharedManager.h"
#import "BGFMDB.h"
#define KeyChainSaveAccountService @"SmartControlService"
#define KeyChainSaveAccount        @"SmartControlAccount"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if(@available(iOS 13.0,*)){
        self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
    self.window.backgroundColor = [UIColor whiteColor];
//    BlueToothViewController *vc = [[BlueToothViewController alloc]init];
    [self getKeychainUUid];
    [self setCustomStyle];
    bg_setSqliteName(@"FanDevice");
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
    
//    CustomNavigationViewController *navi = [[CustomNavigationViewController alloc]initWithRootViewController:vc];
//    self.window.rootViewController = navi;
    self.window.rootViewController = [[TabbarController alloc] init];
    [self.window makeKeyWindow];
    return YES;
}

-(void)setCustomStyle{
    [[UINavigationBar appearance]setBarTintColor:RGB(131, 180, 235)];
    [UINavigationBar appearance].translucent=NO;

    NSDictionary *attributes = @{
        NSForegroundColorAttributeName: [UIColor blackColor], // 标题颜色
        NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0] // 字体
    };
    [[UINavigationBar appearance] setTitleTextAttributes:attributes];
    
    UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
    [appearance configureWithOpaqueBackground];
    
}

-(void)getKeychainUUid{
    NSError *error;
    [SharedManager sharedInstance].uuid = [SSKeychain passwordForService:KeyChainSaveAccountService account:KeyChainSaveAccount error:&error];  //获取密钥
    if ([SharedManager sharedInstance].uuid.length == 0) {
        [SharedManager sharedInstance].uuid = [CommonMethod generateRandomHexString];
        [SSKeychain setPassword:[SharedManager sharedInstance].uuid forService:KeyChainSaveAccountService account:KeyChainSaveAccount];   //设置密钥
    }
}

@end
